package com.eqdd.yiqidian.ui.gongneng.renshi.zuzhiguanli;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.eqdd.nextinputs.StaticScheme;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.box.ItemDecoration.SectionDividerItemDecoration;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditChooseBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity;
import com.eqdd.yiqidian.utils.DensityUtil;
import com.eqdd.yiqidian.utils.SingleChooseUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.eqdd.yiqidian.widget.ActionSheetDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * @author吕志豪 .
 * @date 17-11-29  上午11:51.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class AddCareerDescActivity extends SlimBaseMultiEditActivity {

    private RecyclerViewCustom dataBinding;
    private int id;
    private String postName;
    private String depName;
    private String msg;
    private ActionSheetDialog xingziDialog;
    private ActionSheetDialog xueliDialog;
    private ActionSheetDialog jingyanDialog;
    private ActionSheetDialog gangweiDialog;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_recyclerview);
        initTopTitleBar(View.VISIBLE, "添加岗位描述");
        initTopRightText("添加", v -> {
            if (checkParams()) {
                OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.ADD_CAREER_DESC)
                        .params("companyid", AppConstent.user.getCompanyId())
                        .params("postid", id)
                        .params("postName", postName)
                        .params("depName", depName)
                        .params("jobNature", setParam(2))
                        .params("salaryRange", setParam(3))
                        .params("workdesc", setParam(4))
                        .params("Bzrenshu", setParam(5))
                        .params("educationcla", setParam(6))
                        .params("workexpecla", setParam(7))
                        .params("agecla", setParam(8))
                        .params("sexcla", setParam(9))
                        .params("pfskills", setParam(10))
                        .params("postgenre", setParam(11))
                        .params("creater", AppConstent.user.getGuid())
                        .execute(new DialogCallBack<HttpResult>(AddCareerDescActivity.this) {
                            @Override
                            public void onSuccess(Response<HttpResult> response) {
                                HttpResult httpResult = response.body();
                                ToastUtil.showShort(httpResult.getMsg());
                                if (httpResult.getStatus() == 200) {
                                    clearData();
                                    setResult(Config.SUCCESS);
                                    finish();
                                }
                            }
                        });
            }
        });
    }
    @Override
    protected RecyclerView initRecyclerView() {
        isDefautDivider = false;
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {

        switch (slimAdapterEx.getDataItem(p).getPosition()) {
            case 2:
                if (xingziDialog == null) {
                    SingleChooseUtil.getChooseDialog(this, 38, sheetDialog -> {
                        xingziDialog = sheetDialog;
                        xingziDialog.show();
                    }, (position, strings) -> {
                        slimAdapterEx.getDataItem(p).setContent(strings.get(position - 1));
                        slimAdapterEx.notifyItemChanged(p);
                    });
                } else {
                    xingziDialog.show();
                }
                break;
            case 6:
                if (xueliDialog == null) {
                    SingleChooseUtil.getChooseDialog(this, 39, sheetDialog -> {
                        xueliDialog = sheetDialog;
                        xueliDialog.show();
                    }, (position, strings) -> {
                        slimAdapterEx.getDataItem(p).setContent(strings.get(position - 1));
                        slimAdapterEx.notifyItemChanged(p);
                    });
                } else {
                    xueliDialog.show();
                }
                break;
            case 7:
                if (jingyanDialog == null) {
                    SingleChooseUtil.getChooseDialog(this, 40, sheetDialog -> {
                        jingyanDialog = sheetDialog;
                        jingyanDialog.show();
                    }, (position, strings) -> {
                        slimAdapterEx.getDataItem(p).setContent(strings.get(position - 1));
                        slimAdapterEx.notifyItemChanged(p);
                    });
                } else {
                    jingyanDialog.show();
                }
                break;
            case 11:
                if (gangweiDialog == null) {
                    SingleChooseUtil.getChooseDialog(this, 1, sheetDialog -> {
                        gangweiDialog = sheetDialog;
                        gangweiDialog.show();
                    }, (position, strings) -> {
                        slimAdapterEx.getDataItem(p).setContent(strings.get(position - 1));
                        slimAdapterEx.notifyItemChanged(p);
                    });
                } else {
                    gangweiDialog.show();
                }
                break;
        }
    }

    @Override
    protected void setEditBeans() {
        isSave = false;
        isRead = false;
        id = getIntent().getIntExtra(Config.ID, 0);
        postName = getIntent().getStringExtra("postName");
        depName = getIntent().getStringExtra("depName");
        datas.add(new SlimEditHintBean("岗位名称", postName, 0));
        datas.add(new SlimEditHintBean("所属部门", depName, 1));
        datas.add(new SlimEditEnterBean("工作性质", "", 2, true, "请选择").setNeed(true));
        datas.add(new SlimEditEnterBean("薪资范围", "", 3, "请选择").setNeed(true));

        datas.add(new SlimEditEnterBean("工作描述", "", 4, "请选择").setNeed(true));

        datas.add(new SlimEditEnterBean("编制人数", "", 5, "请选择").addSchemes(StaticScheme.Numeric()).setNeed(true));

        datas.add(new SlimEditEnterBean("学历", "", 6, true, "请选择").setNeed(true));

        datas.add(new SlimEditEnterBean("工作经验", "", 7, true, "请选择").setNeed(true));

        datas.add(new SlimEditEnterBean("年龄", "", 8, "请选择").setNeed(true));

        datas.add(new SlimEditChooseBean("性别", "", 9, "请选择", new String[]{"男", "女", "不限"}).setNeed(true));
        datas.add(new SlimEditEnterBean("专业技能", "", 10, "请选择").setNeed(true));
        datas.add(new SlimEditEnterBean("岗位类别", "", 11, true, "请选择").setNeed(true));

        dataBinding.recyclerView.addItemDecoration(new SectionDividerItemDecoration(AddCareerDescActivity.this, 6, 6)
                .setHeadHeight(DensityUtil.percentW(50))
                .setTitle("岗位信息", "岗位要求")
                .setLeftPadding(DensityUtil.percentW(30))
                .setRightPadding(DensityUtil.percentW(40)));
    }


}
